<?php
class CtrinhbbsController extends AppController {

	var $name = 'Ctrinhbbs';
	var $helpers = array('Html','Javascript', 'Ajax');

	var $uses=array('Bb','Ctrinhbb');

	function index($idct) {
		$this->Ctrinhbb->recursive = 0;
		$this->set('ctrinhbbs', $this->paginate('Ctrinhbb',array('Ctrinhbb.id'=>$idct)));
		$this->set(compact('idct'));
	}
	function timbb($q=null) {
               
      //  print_r($ztkbs);
	   $this->layout = 'ajax';
	   $this->Bb->recursive=-1;
       $this->set('bbs', 
       		$this->Bb->find('list',array(
       			'fields'=>array('id','tenbb'),
       			'conditions'=>array('Bb.tenbb like '=>'%'.$q.'%'))));
       $this->set(compact('q'));
    }

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ctrinhbb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ctrinhbb', $this->Ctrinhbb->read(null, $id));
	}

	function add($idct) {
		if (!empty($this->data)) {
			$this->Ctrinhbb->create();
			if ($this->Ctrinhbb->save($this->data)) {
				$this->Session->setFlash(__('The ctrinhbb has been saved', true));
				$this->redirect(array('action' => 'index',$idct));
			} else {
				$this->Session->setFlash(__('The ctrinhbb could not be saved. Please, try again.', true));
			}
		}
		$ctrinhs = $this->Ctrinhbb->Ctrinh->find('list');
		$bbs = $this->Ctrinhbb->Bb->find('list');
		$this->set(compact('ctrinhs', 'bbs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ctrinhbb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ctrinhbb->save($this->data)) {
				$this->Session->setFlash(__('The ctrinhbb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ctrinhbb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ctrinhbb->read(null, $id);
		}
		$ctrinhs = $this->Ctrinhbb->Ctrinh->find('list');
		$bbs = $this->Ctrinhbb->Bb->find('list');
		$this->set(compact('ctrinhs', 'bbs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ctrinhbb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Ctrinhbb->delete($id)) {
			$this->Session->setFlash(__('Ctrinhbb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Ctrinhbb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
